package com.mayuanfei.handler;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 全局异常处理-实现HandlerExceptionResolver接口方式
 *
 * @author 老马
 * @date 2023-04-04 15:52
 */
//@Component
public class GlobalException2 implements HandlerExceptionResolver {
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ModelAndView mv = new ModelAndView();
        if(ex instanceof ArithmeticException){
            mv.setViewName("error1.jsp");
        }
        if(ex instanceof NullPointerException){
            mv.setViewName("error2.jsp");
        }
        return mv;
    }
}